package view;

import controller.OrderController;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import model.Order;

public class OrderView {
    private OrderController orderController;
    private Scanner scanner;

    public OrderView(OrderController orderController) {
        this.scanner = new Scanner(System.in);
        this.orderController = orderController;
    }

    public void showMenu() {
        while(true) {
            System.out.println("1. 下订单");
            System.out.println("2. 查看订单");
            System.out.println("3. 列出订单");
            System.out.println("4. 处理退款");
            System.out.println("5. 退出");
            int choice = this.scanner.nextInt();
            this.scanner.nextLine();
            switch (choice) {
                case 1:
                    this.placeOrder();
                    break;
                case 2:
                    this.viewOrder();
                    break;
                case 3:
                    this.listOrders();
                    break;
                case 4:
                    this.processRefund();
                    break;
                case 5:
                    return;
            }
        }
    }

    private void placeOrder() {
    }

    private void viewOrder() {
        System.out.print("输入订单ID: ");
        int id = this.scanner.nextInt();
        Order order = this.orderController.getOrder(id);
        if (order != null) {
            System.out.println("订单ID: " + order.getId());
        } else {
            System.out.println("订单未被创建.");
        }

    }

    private void listOrders() {
        List<Order> orders = this.orderController.listOrders();
        Iterator var2 = orders.iterator();

        while(var2.hasNext()) {
            Order order = (Order)var2.next();
            System.out.println("订单ID: " + order.getId());
        }

    }

    private void processRefund() {
        System.out.print("为退款输入订单ID: ");
        int id = this.scanner.nextInt();
        this.orderController.processRefund(id);
        System.out.println("退款处理.");
    }
}
